package com.kang.controller;

import com.kang.bean.Menus;
import com.kang.commons.Result;
import com.kang.service.MenusService;
import com.kang.vo.MenusRoleVo;
import com.kang.vo.MenusVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @program: service
 * @description:
 * @author: K.faWu
 * @create: 2022-02-28 14:16
 **/

@RestController
@RequestMapping("menus")
public class MenusController {

    @Autowired
    private MenusService menusService;

    @GetMapping("/getByRoleCode/{roleCode}")
    public Result<?> getByRoleCode(@PathVariable("roleCode") String roleCode){
        MenusRoleVo vo = menusService.getByRoleCode(roleCode);
        return Result.success(vo);
    }

    @PostMapping
    public Result<?> update(@RequestBody Menus menus){
        menusService.update(menus);
        return Result.success();
    }

    @PutMapping
    public Result<?> add(@RequestBody Menus menus){
        menusService.add(menus);
        return Result.success();
    }

    @GetMapping
    public Result<?> getAll(HttpServletRequest request){
        List<MenusVo> list = menusService.getAll(request);
        return Result.success(list);
    }

    @PostMapping("/delete")
    public Result<?> delete(@RequestBody List<MenusVo> menusVos){
        menusService.delete(menusVos);
        return Result.success();
    }
}
